/*
 * @Description: file content
 * @Author: hwanginsitein
 * @Date: 2021-08-06 23:39:41
 * @LastEditors: hwanginsitein
 * @LastEditTime: 2021-08-07 22:31:20
 * @FilePath: /java/src/Common/UtilBll.java
 */

import java.io.*;
import java.util.Objects;
import java.util.Properties;
import java.util.Random;

public class Utilbll {

    private final static int LOWER_CASE_COUNT = 26;
    private final static int UPPER_CASE_COUNT = 26;

    public static void outputGap() {
        System.out.println("-------------------------------------------------------------------");
    }

    public static String randomString(int num) {
        char[] tmp = new char[num];
        Random r = new Random();
        for (int i = 0; i < num; i++) {
            if (r.nextBoolean()) {
                tmp[i] = (char) ('a' + r.nextInt(LOWER_CASE_COUNT - 1));
            } else {
                tmp[i] = (char) ('A' + r.nextInt(UPPER_CASE_COUNT - 1));
            }
        }
        return new String(tmp);
    }

    public static char[] alphabetChars() {
        char[] chars = new char[LOWER_CASE_COUNT + UPPER_CASE_COUNT];
        int j = 0;
        for (char i = 'A'; i <= 'Z'; i++) {
            chars[j] = i;
            j++;
        }
        for (char i = 'a'; i <= 'z'; i++) {
            chars[j] = i;
            j++;
        }
        return chars;
    }

    public static String alphabet() {
        char[] chars = alphabetChars();
        return new String(chars);
    }

    public static String projectDir() {
        return Objects.requireNonNull(Utilbll.class.getResource("/")).getPath();
    }

    public static String getProperty(String property) throws IOException {
        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("config.properties");
        Properties pros = new Properties();
        pros.load(is);
        return pros.getProperty(property);
    }

    public static String fileGetContent(String filePath) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(filePath);
        StringBuilder content = new StringBuilder();
        int tmp;
        byte[] b = new byte[fileInputStream.available()];
        fileInputStream.read(b);
        return new String(b);
//        while ((tmp = fileInputStream.read()) != -1) {
//            content.append(tmp);
//        }
//        return content.toString();
    }
}